package Func;

import Book.Book;
import Book.BookList;

import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 38917
 * Date: 2025-02-16
 * Time: 02:17
 */
public class BorrowFunc implements Func{
    @Override
    public void work(BookList bookList) {
        Scanner in = new Scanner(System.in);
        System.out.println("请输入你要借阅的书名");
        String name = in.nextLine();
        int curSize = bookList.getUsedSize();
        for (int i = 0; i < curSize; i++) {
            Book book = bookList.getBooks(i);   //获取书架中下标为 i 的图书
            if (book.getName().equals(name)){
                if (!book.getBoolean()){
                    book.setBoolean(true);
                    System.out.println("借阅成功");
                }else {
                    System.out.println("已经被借阅了");
                }
                return;//结束方法
            }
        }
        System.out.println("没有你要借阅的图书");
    }
}
